#include "RectangleP.h"


RectangleP::RectangleP( float x1, float y1, float x2, float y2,Material *mat,Texture *tex) : Primitive(mat,tex)
{
	this->x1=x1;
	this->y1=y1;
	this->x2=x2;
	this->y2=y2;
}

void RectangleP::act(float texLS, float texLT)
{
	getMat()->act();
	getTex()->act();

	float ls,lt;
	if(tex->inheritTex){
		ls=texLS;
		lt=texLT;
	}
	else{
		ls=getTex()->getLengthS();
		lt=getTex()->getLengthT();
	}

	float xx = (x2-x1)  /ls;
	float yy = (y2-y1)  /lt;
	
	
	glBegin(GL_POLYGON);
		glNormal3d(0, 0, 1);
		glTexCoord2f(0.0, 0.0); 
		glVertex3f(x1, y1, 0);
		glTexCoord2f(xx, 0.0); 
		glVertex3f(x2, y1, 0);
		glTexCoord2f(xx, yy); 
		glVertex3f(x2, y2, 0);
		glTexCoord2f(0.0, yy); 
		glVertex3f(x1, y2, 0);
	glEnd();
	
}
